﻿using System;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Text;

namespace Net
{
	public static class Helpers
	{
		public static string EncryptMD5(string text)
		{
			UnicodeEncoding UE = new UnicodeEncoding();
			byte[] hashValue;
			byte[] message = UE.GetBytes(text);

			MD5 hashString = new MD5CryptoServiceProvider();
			string hex = "";

			hashValue = hashString.ComputeHash(message);
			foreach (byte x in hashValue)
			{
				hex += String.Format("{0:x2}", x);
			}
			return hex;
		}

		public static string EncryptSHA1(string text)
		{
			UnicodeEncoding UE = new UnicodeEncoding();
			byte[] hashValue;
			byte[] message = UE.GetBytes(text);

			SHA1Managed hashString = new SHA1Managed();
			string hex = "";

			hashValue = hashString.ComputeHash(message);
			foreach (byte x in hashValue)
			{
				hex += String.Format("{0:x2}", x);
			}
			return hex;
		}

		public static string EncryptSHA256(string text)
		{
			UnicodeEncoding UE = new UnicodeEncoding();
			byte[] hashValue;
			byte[] message = UE.GetBytes(text);

			SHA256Managed hashString = new SHA256Managed();
			string hex = "";

			hashValue = hashString.ComputeHash(message);
			foreach (byte x in hashValue)
			{
				hex += String.Format("{0:x2}", x);
			}
			return hex;
		}

		public static string EncryptSHA512(string text)
		{
			UnicodeEncoding UE = new UnicodeEncoding();
			byte[] hashValue;
			byte[] message = UE.GetBytes(text);

			SHA512Managed hashString = new SHA512Managed();
			string hex = "";

			hashValue = hashString.ComputeHash(message);
			foreach (byte x in hashValue)
			{
				hex += String.Format("{0:x2}", x);
			}
			return hex;
		}
	}
}